define(['./PageView', 'jquery', '../libs/canlendar', '../libs/AjaxUtil', '../libs/CommonTools', '../libs/GetAction', '../libs/util'], function (PageView, $, Canlendar, AjaxUtil, CommonTools, GetAction, util) {

    return PageView.extend({
        events:{
            'click .row-block': 'selectType',
        },
        initialize: function () {
            require('../../less/SelectGoalType.less');
        },
        render: function () {
            PageView.prototype.render.apply(this, arguments);
            var tpl = require('../templates/SelectGoalType.html');
            this.$main = $('<div class="main"></div>');
            this.$wrap = $('<div class="content"></div>');
            this.$wrap.append(tpl);
            this.$main.append(this.$wrap);
            this.$el.append(this.$main);
            return this;
        },
        onRender: function(){
            //获取组织部门,最上级
            var _this = this;
            AjaxUtil.ajaxPost({
                path: '/client/dept/my',
                params: {},
                success: function (data) {
                    if(data.length != 0){
                        //把获得的部门渲染到页面
                        for(var i=0 ; i<data.length ; i++){
                            var liHtml;
                            liHtml = '<li class="depart-list-li"><div class="row-block" data-type="2" data-value="'+ data[i].deptName +'" data-id="'+ data[i].deptId +'">'+ data[i].deptName +'</div></li>';
                            _this.$el.find('.goal-depart-list').append(liHtml);
                        }
                    }
                    else{
                        CommonTools.Toast('获取部门信息失败!');
                    }

                },
                error: function () {
                    CommonTools.Toast('请检查网络!');
                }
            });
        },
        selectType: function(e){
            var valueStr = $(e.target).attr('data-value');
            var type = $(e.target).attr('data-type');
            window.app.valueStr = valueStr;
            window.app.type = type;
            this.$el.find('.row-block').removeClass('selected');
            $(e.target).addClass('selected');
            window.history.back();
        },
    });
});